package com.ruoyi.web.controller.file;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.my.domain.MyProjectPagingList;
import com.ruoyi.my.domain.MySectionProject;
import com.ruoyi.my.service.MySectionProjectService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author SR
 * @date 2022/5/20
 */
@RestController
@RequestMapping("/project")
public class MyProjectController extends BaseController {
    @Autowired
    MySectionProjectService mySectionProjectService;

//    根据菜单信息获取项目列表
    @PreAuthorize("@ss.hasAnyPermi({'my:sectionProject:list', 'epc:2021:list', 'epc:2022:list', 'epc:2023:list'})")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = "menu") String menu, @RequestParam(value = "menuName") String menuName){
        Integer total_num = mySectionProjectService.selectMySectionProjectListBymenu(menu,menuName).size();
        startPage();
        List<MySectionProject> projectList = mySectionProjectService.selectMySectionProjectListBymenu(menu,menuName);
        return AjaxResult.success(new MyProjectPagingList(total_num,projectList));
    }

//    删除项目
    @PreAuthorize("@ss.hasAnyPermi({'my:sectionProject:removes', 'epc:2021:remove', 'epc:2022:remove', 'epc:2023:remove'})")
    @PostMapping("/delect")
    public AjaxResult remove(@RequestParam(value = "id") Integer id){
        return AjaxResult.success(mySectionProjectService.remove(id));
    }

//    增加新项目
    @PreAuthorize("@ss.hasAnyPermi({'my:sectionProject:add', 'epc:2021:add', 'epc:2022:add', 'epc:2023:add'})")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MySectionProject mySectionProject){
        return AjaxResult.success(mySectionProjectService.add(mySectionProject));
    }

//    修改项目信息
    @PreAuthorize("@ss.hasAnyPermi({'my:sectionProject:update', 'epc:2021:edit', 'epc:2022:edit', 'epc:2023:edit'})")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody MySectionProject mySectionProject){
        return AjaxResult.success(mySectionProjectService.update(mySectionProject));
    }

}
